package com.wf.it.hpplan.dao;

import com.wf.it.common.entity.Book;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;

import java.util.List;

public interface BookDao extends JpaRepository<Book,Integer> , JpaSpecificationExecutor<Book> {

    List<Book> findByUserIdCard(String userIdCard);
    @Modifying
    @Query(value="update Book set state=?2 where id=?1")
    void updateBookState(int bookid, int state);
    @Modifying
    @Query(nativeQuery=true
            ,value="update books b " +
                    "join plans p on b.book_planid=p.plan_id " +
                    "set b.book_state=3 " +
                    "where b.book_state=1 and DATEDIFF(p.plan_workdate,now())<0")
    void updateBookState2Finish();
}
